//////////////////////////////////////////////////////////////////////////////////
//	File	:	GamePlayState.cpp
//	Author	:	Yuri Oyoko
//	Purpose	:	This state defines the main menu state of the game and its behavior
//////////////////////////////////////////////////////////////////////////////////

//Includes
#include "MultiPlayerTestState.h"
#include "SGD Wrappers/CSGD_Direct3D.h"
#include "SGD Wrappers/CSGD_DirectInput.h"
#include "SGD Wrappers/CSGD_TextureManager.h"
#include "SGD Wrappers/CSGD_WaveManager.h"
#include "CAnimation_Manager.h"


MultiPlayerTestState::MultiPlayerTestState()
{
}
MultiPlayerTestState::~MultiPlayerTestState()
{
}
MultiPlayerTestState* MultiPlayerTestState::GetInstance()
{
	static MultiPlayerTestState menuStateInstance;
	return &menuStateInstance;
}
void MultiPlayerTestState::Enter()
{

		

	TopViewPort.X = 0;
	TopViewPort.Y = 0;
	TopViewPort.Width = 800;
	TopViewPort.Height = 300;
	TopViewPort.MinZ = 0.0f;
	TopViewPort.MaxZ = 1.0f;

	BotViewPort.X = 0;
	BotViewPort.Y = 300;
	BotViewPort.Width = 800;
	BotViewPort.Height = 300;
	BotViewPort.MinZ = 0.0f;
	BotViewPort.MaxZ = 1.0f;


	timer = 0.0f;
	Player.SetPositionX(800);
	Player.SetPositionY(600);

	Player2.SetPositionX(800);
	Player2.SetPositionY(600);
	
	vector<int> CreatedIDs;

	if(CAnimation_Manager::GetInstance()->LoadAnimations("Animations\\boomer_anim.abn", &CreatedIDs))
	{
		Player.SetImageID(CreatedIDs[0]);
	}
	CreatedIDs.clear();

	if(CAnimation_Manager::GetInstance()->LoadAnimations("Animations\\francis.abn", &CreatedIDs))
	{
		Player2.SetImageID(CreatedIDs[0]);
	}
	BGID = CSGD_TextureManager::GetInstance()->LoadTexture("tests\\CameraTest.png");

	Cam.InitializeCamera(0,0,800,300,&Player);
	Cam2.InitializeCamera(0,300,800,300,&Player2);


}
void MultiPlayerTestState::Exit()
{
}
bool MultiPlayerTestState::GetInput()
{
	return true;
}
void MultiPlayerTestState::Update(float theElapsedTime)
{
	CAnimation_Manager::GetInstance()->Update(theElapsedTime);
	Cam.Update();
	Cam2.Update();
	
	if(timer > 5)
	{
		timer = 0;
	}
	timer += theElapsedTime;

		if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_Q))
		{
			CAnimation_Manager::GetInstance()->PlayAnimation(0);
		}
		if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_W))
		{
			CAnimation_Manager::GetInstance()->PauseAnimation(0);
		}
		if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_E))
		{
			CAnimation_Manager::GetInstance()->StopAnimation(0);
		}
		if(CSGD_DirectInput::GetInstance()->KeyDown(DIK_LEFT))
		{
			Player.SetPositionX(Player.GetPositionX() - 50*theElapsedTime);
		}
		if(CSGD_DirectInput::GetInstance()->KeyDown(DIK_RIGHT))
		{
			Player.SetPositionX(Player.GetPositionX() + 50*theElapsedTime);
		}
		if(CSGD_DirectInput::GetInstance()->KeyDown(DIK_UP))
		{
			Player.SetPositionY(Player.GetPositionY() - 50*theElapsedTime);
		}
		if(CSGD_DirectInput::GetInstance()->KeyDown(DIK_DOWN))
		{
			Player.SetPositionY(Player.GetPositionY() + 50*theElapsedTime);
		}


		//Player 2;
		if(CSGD_DirectInput::GetInstance()->KeyDown(DIK_A))
		{
			Player2.SetPositionX(Player2.GetPositionX() - 50*theElapsedTime);
		}
		if(CSGD_DirectInput::GetInstance()->KeyDown(DIK_D))
		{
			Player2.SetPositionX(Player2.GetPositionX() + 50*theElapsedTime);
		}
		if(CSGD_DirectInput::GetInstance()->KeyDown(DIK_W))
		{
			Player2.SetPositionY(Player2.GetPositionY() - 50*theElapsedTime);
		}
		if(CSGD_DirectInput::GetInstance()->KeyDown(DIK_S))
		{
			Player2.SetPositionY(Player2.GetPositionY() + 50*theElapsedTime);
		}
		
			

	
}
void MultiPlayerTestState::Render()
{


	CSGD_Direct3D::GetInstance()->GetDirect3DDevice()->SetViewport(&TopViewPort);
	
	//D3DXMATRIX Ident;
	//D3DXMatrixIdentity(&Ident);

	//CSGD_Direct3D::GetInstance()->GetDirect3DDevice()->SetTransform(D3DTS_VIEW, &Ident);
	

	CSGD_Direct3D::GetInstance()->Clear(0,0,0);
	CSGD_Direct3D::GetInstance()->DeviceBegin();
	CSGD_Direct3D::GetInstance()->SpriteBegin();

	CSGD_TextureManager::GetInstance()->Draw(BGID,0-Cam.GetCameraXOffset(),0-Cam.GetCameraYOffset());
	CAnimation_Manager::GetInstance()->Draw(Player.GetPositionX()-Cam.GetCameraXOffset(), Player.GetPositionY() - Cam.GetCameraYOffset(),  Player.GetImageID());
	CAnimation_Manager::GetInstance()->Draw(Player2.GetPositionX()-Cam.GetCameraXOffset(), Player2.GetPositionY() - Cam.GetCameraYOffset(),  Player2.GetImageID());
	

	CSGD_Direct3D::GetInstance()->SpriteEnd();
	CSGD_Direct3D::GetInstance()->DeviceEnd();
	//CSGD_Direct3D::GetInstance()->Present();

	CSGD_Direct3D::GetInstance()->GetDirect3DDevice()->SetViewport(&BotViewPort);
	
	//D3DXMATRIX trans;
	//D3DXMatrixTranslation(&trans, 0.0f,300.0f,0.0f);

	//CSGD_Direct3D::GetInstance()->GetDirect3DDevice()->SetTransform(D3DTS_VIEW, &trans);
	//
	CSGD_Direct3D::GetInstance()->Clear(0,0,0);
	CSGD_Direct3D::GetInstance()->DeviceBegin();
	CSGD_Direct3D::GetInstance()->SpriteBegin();

	CSGD_TextureManager::GetInstance()->Draw(BGID,0-Cam2.GetCameraXOffset(),0-Cam2.GetCameraYOffset());
	CAnimation_Manager::GetInstance()->Draw(Player.GetPositionX()-Cam2.GetCameraXOffset(), Player.GetPositionY() - Cam2.GetCameraYOffset(),  Player.GetImageID());
	CAnimation_Manager::GetInstance()->Draw(Player2.GetPositionX()-Cam2.GetCameraXOffset(), Player2.GetPositionY() - Cam2.GetCameraYOffset(),  Player2.GetImageID());
	
	CSGD_Direct3D::GetInstance()->SpriteEnd();
	CSGD_Direct3D::GetInstance()->DeviceEnd();


	CSGD_Direct3D::GetInstance()->Present();


}